package cn.school.dao;

import cn.school.entity.Subject;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface SubjectDao {

    @Delete("delete from s_subject where id=#{0}")
    public int del(long id);

    @Select("select subjectname as name,gradeid,classhour,id from s_subject where id=#{0}")
    public Subject get(long id);

    @Insert("insert into s_subject(subjectname,classhour,gradeid)values(#{name},#{classhour},#{gradeid})")
    public int add(Subject o);

    //查询并分页
    @Select("<script><bind name=\"start\" value=\"(pageNo-1)*pageSize\"/>" +
            "select subjectname as name,gradeid,classhour,id from s_subject "
            + "<where><if test=\"subname!=null\"> and subjectname like \"%\"#{subname}\"%\"</if></where>"
    +" limit #{start},#{pageSize}</script>")

    public List<Subject> search(@Param("subname") String subname, @Param("pageNo") int pageNo, @Param("pageSize") int pageSize);

    @ResultType(int.class)
    @Select("<script>" +
            "select count(1) from s_subject "
            + "<where><if test=\"subname!=null\"> and subjectname like \"%\"#{subname}\"%\"</if></where>"+
          "</script>")
    public int searchTotal(@Param("subname") String subname);
}
